package com.maxima.attendance.pojos;

import java.text.SimpleDateFormat;

public class Employee {
	private Integer id;
	private String firstName;
	private String lastName;
	private String password;
	private Integer employeeId;
	private Boolean loggedIn;
	private Boolean loggedOut;
	private String timeIn;
	private String timeOut;
	private Boolean workFromHome;
	private Boolean absent;
	private Integer timeLogId;
	SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

	public Employee(User user, TimeLog timeLog) {
		if (user != null) {
			this.id = user.getId();
			this.employeeId = user.getEmployeeId();
			this.firstName = user.getFirstName();
			this.lastName = user.getLastName();
			this.password = user.getPassword();
		}
		setTimeLog(timeLog);
	}

	public void setTimeLog(TimeLog timeLog) {
		if (timeLog == null) {
			this.setLoggedIn(false);
			this.setLoggedOut(false);
			this.timeIn = null;
			this.timeOut = null;
			this.workFromHome = false;
			this.absent = true;
			this.timeLogId = -1;
		} else if (timeLog.getWorkFromHome()) {
			this.setLoggedIn(false);
			this.setLoggedOut(false);
			this.timeIn = null;
			this.timeOut = null;
			this.workFromHome = true;
			this.absent = false;
			this.timeLogId = timeLog.getId();
		} else if (timeLog.getLogoutTime() == null) {
			this.setLoggedIn(true);
			this.setLoggedOut(false);
			this.timeIn = timeFormat.format(timeLog.getLoginTime());
			this.timeOut = null;
			this.workFromHome = false;
			this.absent = false;
			this.timeLogId = timeLog.getId();
		} else {
			this.setLoggedIn(false);
			this.setLoggedOut(true);
			this.timeIn = timeFormat.format(timeLog.getLoginTime());
			this.timeOut = timeFormat.format(timeLog.getLogoutTime());
			this.workFromHome = false;
			this.absent = false;
			this.timeLogId = timeLog.getId();
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Employee && this.employeeId.equals(((Employee) obj).getEmployeeId())) {
			return true;
		}
		return false;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Integer getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(Integer employeeId) {
		this.employeeId = employeeId;
	}

	public String getTimeIn() {
		return timeIn;
	}

	public void setTimeIn(String timeIn) {
		this.timeIn = timeIn;
	}

	public String getTimeOut() {
		return timeOut;
	}

	public void setTimeOut(String timeOut) {
		this.timeOut = timeOut;
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Boolean getWorkFromHome() {
		return workFromHome;
	}

	public void setWorkFromHome(Boolean workFromHome) {
		this.workFromHome = workFromHome;
	}

	public Boolean getAbsent() {
		return absent;
	}

	public void setAbsent(Boolean absent) {
		this.absent = absent;
	}

	public Boolean getLoggedIn() {
		return loggedIn;
	}

	public void setLoggedIn(Boolean loggedIn) {
		this.loggedIn = loggedIn;
	}

	public Boolean getLoggedOut() {
		return loggedOut;
	}

	public void setLoggedOut(Boolean loggedOut) {
		this.loggedOut = loggedOut;
	}

	public Integer getTimeLogId() {
		return timeLogId;
	}

	public void setTimeLogId(Integer timeLogId) {
		this.timeLogId = timeLogId;
	}
}